var webpack = require('webpack')
var HtmlwebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var merge = require('webpack-merge')
var webpackBaseConfig = require('./webpack.config.js')
var uglifyJsPlugin = require('uglifyjs-webpack-plugin')
var VueLoaderPlugin = require('vue-loader/lib/plugin')

//清空基本配置的插件列表

webpackBaseConfig.plugins = []

module.exports = merge(webpackBaseConfig, {
  output:{
    publicPath:'./',
    //将入口文件重命名为20位的hash值得唯一文件
    filename: '[name].[hash].js'
  },
  plugins:[
    new VueLoaderPlugin(),
    new ExtractTextPlugin({
      // 提取css，并重命名为带有20位hash的唯一文件
      filename: '[name].[hash].css',
      allChunks: true
    }),
    // 定义当前node环境为生成环境
    new webpack.DefinePlugin({
      'process.env': {
        NODE_EVN: '"production"'
      }
    }),
    // 提取模板，并保存入口html文件
    new HtmlwebpackPlugin({
      filename: './index_prod.html',
      template: './app/index.ejs',
      inject: false
    })
  ],
  optimization: {
    minimizer: [
      new uglifyJsPlugin({
        uglifyOptions: {
          compress: false
        }
      })
    ]
  }
})